<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>上传控件</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
    <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
    <!--[if lte IE 6]>
    <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap-ie6.css">
    <![endif]-->
    <!--[if lte IE 7]>
    <link rel="stylesheet" type="text/css" href="bootstrap/css/ie.css">
    <![endif]-->
    <link rel="stylesheet" href="leipi.style.css">
    <script type="text/javascript" src="../dialogs/internal.js"></script>
    <script type="text/javascript">
/* Thank you by  
http://www.alt-tag.com/blog/2006/02/ie-dom-bugs/ */
function createInput(type, name, value) {
    var element = document.createElement('input');
    element.type = type;
    element.name = name;
    element.value = value;
    return element;
}
    </script>
</head>
<body>
<div class="content">
    <table class="table table-bordered table-striped table-hover">
     <tr>
        <th><span>字段名称</span><span class="label label-important">*</span></th>
        <th><span>按钮标题</span><span class="label label-important">*</span> </th>
    </tr>
    <tr>
        <td><input type="text" id="fieldname" placeholder="必填项"></td>
        <td><input type="text" id="orgname" placeholder="必填项"></td>
    </tr>
    <tr>
        <th><span>上传类型</span> </th>
        <th><span>对齐方式</span> </th>
    </tr>
    <tr>
        <td>
             <select id="filetype">
                 <option value="file">所有文件</option>
                 <option value="image">图片文件</option>
                 <option value="zipfile">压缩文件</option>
                 <option value="video">视频文件</option>
                 <option value="audio">音频文件</option>
            </select>
        </td>
        <td>
            <select id="orgalign">
                <option value="left" >左对齐</option>
                <option value="center">居中对齐</option>
                <option value="right">右对齐</option>
            </select>
        </td>
    </tr>
    </table>
</div>
<script type="text/javascript">
var oNode = null,thePlugins = 'upload';
window.onload = function() {
    if( UE.plugins[thePlugins].editdom ){
        oNode = UE.plugins[thePlugins].editdom;
		var gName=oNode.getAttribute('fieldname'),gTitle=oNode.getAttribute('title').replace(/&quot;/g,"\""),gAlign=oNode.getAttribute('orgalign'),gType=oNode.getAttribute('filetype');
        gTitle = gTitle==null ? '' : gTitle;
        gName = gName==null ? '' : gName;
        $G('orgname').value = gTitle;
        $G('fieldname').value = gName;
        $G('orgalign').value = gAlign;
        $G('filetype').value = gType;
    }
}
dialog.oncancel = function () {
    if( UE.plugins[thePlugins].editdom ) {
        delete UE.plugins[thePlugins].editdom;
    }
};
dialog.onok = function (){
    if($G('fieldname').value==''){
        alert('请输入字段名称');
        return false;
    }
    if($G('orgname').value==''){
        alert('请输入控件名称');
        return false;
    }
    var gTitle=$G('orgname').value.replace(/\"/g,"&quot;"),gName=$G('fieldname').value,gAlign=$G('orgalign').value,gType=$G('filetype').value;
    
    if( !oNode ) {
        try {
            oNode = createInput('button', '', gTitle);
            oNode.setAttribute('type','button');
            oNode.setAttribute('fieldname',gName);
            oNode.setAttribute('plugins',thePlugins);
            oNode.setAttribute('filetype',gType);
            oNode.setAttribute('title',gTitle);
            oNode.setAttribute('class','fsduploadfield');

            var hiddenNode = createInput('hidden', gName, '');
            hiddenNode.setAttribute('fieldname',gName);
            hiddenNode.setAttribute('plugins',thePlugins);
            hiddenNode.setAttribute('title',gTitle);

            if( gAlign != '' ) {
                //style += 'text-align:' + gAlign + ';';
                oNode.style.textAlign = gAlign;
                oNode.setAttribute('orgalign',gAlign );
            }
            if( gType != '' ) {
                oNode.setAttribute('filetype',gType );
            }
            //oNode.setAttribute('style',style );
            //oNode.style.cssText=style;//ie7
            var divelement = document.createElement('fsd');
            divelement.setAttribute('plugins',thePlugins);
            divelement.append(oNode);
            divelement.append(hiddenNode);
            editor.execCommand('insertHtml',divelement.outerHTML);
        } catch (e) {
            try {
                editor.execCommand('error');
            } catch ( e ) {
                alert('控件异常，请联系技术支持');
            }
            return false;
        }
    } else {
        
        oNode.setAttribute('title', gTitle);
        oNode.setAttribute('fieldname',gName);
        oNode.setAttribute('class','fsduploadfield layui-btn');
        if( gAlign != '' ) {
            oNode.style.textAlign = gAlign;
            oNode.setAttribute('orgalign',gAlign );
        }else{
            oNode.setAttribute('orgalign', '');
        }
        if( gType != '' ) {
            oNode.setAttribute('filetype',gType );
        }else{
            oNode.setAttribute('filetype', '');
        }
        delete UE.plugins[thePlugins].editdom;
    }
};
</script>
</body>
</html>